import api from '../../api/api'
import * as types from '../mutation-types'

// initial state
const state = {
    allRegionWeathers: {},
}

/**
 * 这里的getter永远都会将state传入。
 * getters
 */
const getters = {
    allRegionWeathers: state => state.allRegionWeathers,
}

/**
 * actions
 * 这个包含的是 commit 和 state 或者只包含commit
 * @type {{getHotSpotList: (({ commit, state }:{commit: *, state: *}))}}
 */
const actions = {
    getRegionsWeatherCollection({commit, state}) {
        api.getWeatherForecast((list)=> {
            commit(types.UPDATE_WEATHER_STATE, {list})
        })
        console.log("_____action____________UPDATE_WEATHER_STATE")
    }

}

/**
 * 多个mutation可以接收同一个action
 * mutations
 * 执行语句
 * @type {{}}
 * 特别注意参数 {}
 */
const mutations = {
    [types.UPDATE_WEATHER_STATE](state, {list}){
        state.allRegionWeathers = list;
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}
